def debupe(items):
    seen = set()
    for item in items:
        if item not in seen:
            yield item
            seen.add(item)


a = [1, 5, 2, 1, 9, 1, 5, 1, 10]
print('将{}列表去掉重复元素后\n为{}'.format(a, list(debupe(a))))

print('*'*30+'EXAMPLE 1:'+'*'*50)


def dedupe1(items1, key=None):
    seen = set()
    for item in items1:
        val = item if key is None else key(item)
        if val not in seen:
            yield item
            seen.add(val)


b = [{'x': 1, 'y': 2}, {'x': 1, 'y': 3}, {'x': 1, 'y': 2}, {'x': 2, 'y': 4}]
lb1 = list(dedupe1(b, key=lambda d: (d['x'], d['y'])))
print(lb1)

print('*'*30+'EXAMPLE 2:'+'*'*50)

rows = [
    {'address': '5412 N CLARK', 'date': '07/01/2012'},
    {'address': '5148 N CLARK', 'date': '07/04/2012'},
    {'address': '5800 E 58TH', 'date': '07/02/2012'},
    {'address': '2122 N CLARK', 'date': '07/03/2012'},
    {'address': '5645 N RAVENSWOOD', 'date': '07/02/2012'},
    {'address': '1060 W ADDISON', 'date': '07/02/2012'},
    {'address': '4801 N BROADWAY', 'date': '07/01/2012'},
    {'address': '1039 W GRANVILLE', 'date': '07/04/2012'},
        ]
from operator import itemgetter
from itertools import groupby

rows.sort(key=itemgetter('date'))
for date, items in groupby(rows, key=itemgetter('date')):
    print(date)
    for i in items:
        print('', i)

print('*' * 30 + 'EXAMPLE 3:' + '*' * 50)

values = ['1', '2', '-3', '-', '4', 'N/A', '5']


def is_int(val):
    try:
        x = int(val)
        return True
    except ValueError:
        return False


ivals = list(filter(is_int, values))
print(ivals)


print('*' * 30 + 'EXAMPLE 3:' + '*' * 50)

my_list = [1, 4, -5, 10, -7, 2, 3, -1]
import math
sqrt_list = [math.sqrt(n) for n in my_list if n > 0]
print(sqrt_list)